# class A(object): # 默认是继承的object类
#     xxx = 333
#     def run(self):
#         print("我是父类的方法")
# class B(A): # B类继承了A类
#     xxx = 222
#     def run(self):
#         print("我是子类的方法")
# b1 = B() # 通过B类创建对象
# b1.run()
"""
通过子类创建的对象： 
如果子和父有重名的方法，优先走子类，子类没有找父类
"""
# print(b1.xxx)
"""
通过子类创建的对象： 
如果子和父有重名的类属性，优先走子类，子类没有找父类
"""
# b1.xxx = 999
# print(b1.xxx) # 999
# 对象属性<——类<——父类
#
#  利用继承来解决类和类之间的代码冗余问题
"""
class Peple:
    school = '不造啊'
    def __init__(self,name,age,sex):
        self.name = name
        self.age = age
        self.sex = sex
class Student(Peple):
    def play(self):
        print("%s play football"%self.name)
class Teacher(Peple):
    def course(self):
        print("%s course"%self.name)
# 通过Student类实例化对象
s1 = Student("关博文",29,"女")
s1.play()
# 通过Teacher实例化对象
t1 = Teacher("小白",33,'男')
t1.course()
"""
# 但是这里有个问题子类有新的属性需要实例化的时候参数怎么办
# 子类派生的新方法中重用父类功能：方法一
"""
class Peple:
    school = '不造啊'
    def __init__(self,name,age,sex):
        self.name = name
        self.age = age
        self.sex = sex
class Student():
    
    #在Student类里，派生了属于Student自己的实例属性：score
    
    def __init__(self,name,age,sex,score=0):
        Peple.__init__(self,name,age,sex)
        self.score = score
    def play(self):
        print("%s play football"%self.name)
class Teacher(Peple):
    #Teacher类里，派生了属于Teacher自己的实例属性：hobby
    def __init__(self,name,age,sex,hobby):
        Peple.__init__(self,name,age,sex)
        self.hobby = hobby
    def course(self):
        print("%s course"%self.name)
# 通过Student类实例化对象
stu1 = Student('小龙',30,'male',100)
print(stu1.__dict__)
stu1.play()
# 通过Teacher类实例化对象
t1 = Teacher("小白",30,'男','篮球')
t1.course()
"""
# 子类派生的新方法中重用父类功能：方法二
"""
class People:
    school = '不造呀'
    def __init__(self, name, age, sex):
        self.name = name
        self.age = age
        self.sex = sex
class Student(People):
    '''
    派生实例化除了父类的属性添加，还能有自己独有的属性 ******
    在子类派生出的新方法中重用父类功能的方式二:super()必须在类中用
    super(自己的类名,自己的对象)
    可以省略传值
    super()
    '''
    def __init__(self,name,age,sex,score = 0):
        super().__init__(name, age, sex)
        # super(Student,self).__init__(name,age,sex) # 可以省略传值：类名和self对象本身
        self.score = score
    def play(self):
        print("%s play football"%self.name)

s1 = Student("关博文",99,'男',100) # name,age,sex,score = 0
s1.play()
"""

# 在单继承背景下的属性查找
# 对象——>对象的类——>父类——>父类的父类
"""
class Foo():
    xxx = 444
    pass
class Bar1(Foo):
    # xxx = 333
    pass
class Bar2(Bar1):
    # xxx = 222
    pass
obj = Bar2()
obj.xxx = 555
print(obj.xxx) # 555
"""

# 在多继承背景下的属性查找
"""
class G(object):
    x = 'G'
    pass
class E(G):
    #x = 'E'
    pass
class F(G):
    #x = 'F'
    pass
class B(E):
    # x = 'E'
    pass
class C(F):
    #x='C'
    pass
class D(G):
    #x='D'
    pass
class A(B,C,D):
    # x = 'A'
    pass
obj = A()
print(obj.x)

# python专门为继承类内置了一个mro的方法,用来查看c3算法的计算结果
print(A.mro())
"""


